#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main(void)
{
    int status;
    pid_t id=fork();
    if(id==0)
    {
        for(int i=0;i<10;i++)
        {
            printf("child-pid:%d,ppid:%d\n",getpid(),getppid());
            sleep(1);
        }
        exit(0);
    }
    while(1)
    {
        pid_t ret=waitpid(id,&status,WNOHANG);
        if(ret==0)//等待成功，子进程还没退出,父进程可以干自己的任务
        {
            printf("father process is doing other thing...\n");
        }
        else if(ret>0)//等待成功，子进程退出 
        {
           printf("ret=%d,father-pid:%d,ppid:%d\n",ret,getpid(),getppid());
           break;
        }
        else //等待失败
        {
            printf("wait failed\n");
            break;
        }
        sleep(4);
    }

    return 0;
}
